<template>
	<view class="content">
		<view class="searchbox">
			<u-search placeholder="搜索药品" v-model="keyword" :show-action="false" bg-color="#f2f2f2" @search="search"></u-search>
		</view>
		<u-row>
			<view class="second-font">
				搜索结果({{baseDrug.length}}条)
			</view>
		</u-row>
		<view v-for="drug in baseDrug">
			<view class="medicinecard">
				<medicinecard :drug="drug" :index="index"/>
			</view>
		</view>
	</view>
</template>

<script>
	import medicinecard from "../../component/medicinecard.vue"
	export default {
		data(){
			return{
				index:0,
				keyword:'',
				baseDrug:[]
			}
		},
		components:{
			medicinecard
		},
		methods:{
			search(){
				console.log("搜索"+this.keyword)
				uni.request({
				    url: getApp().globalData.hostip+'Demo/drug/search?key='+this.keyword, 
				    data: {
				    },
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						this.baseDrug=res.data;
						console.log(res.data)
				    }
				});
			}
		},
		created(){
			this.baseDrug=getApp().globalData.baseDrug;
		},
		onLoad:function (option){
			this.index=option.index
		}
	}
</script>

<style scopped>
	page{
		background-color: #f5f5f5;
	}
	.searchbox{
		background-color: #1477FE;
		padding: 28rpx;
	}
	.u-row{
		margin: 20rpx 20rpx;
	}
</style>
